import React, { Component } from 'react';
import { Text, Image, View, TextInput, TouchableOpacity } from 'react-native';
import { unitWidth } from '../constants/AdapterUtil';
import { MyHeader } from '../components/MyHeader';
import Colors from '../constants/Colors';
import { postFetch } from '../constants/HttpExtension';
import { show } from '../constants/Toast';
import { api_member_info_Certification, api_member_info_addBank, api_member_info_SubAccount } from '../constants/HttpServices';
import { SubmitButton1 } from '../components/Button';
import { MyInput1 } from '../components/Input';
import TextUtil from '../constants/TextUtil';
import { ExamineView } from '../components/EmptyView';

export default class AddAccountScreen extends Component {

    constructor(props) {
        super(props)

        const { navigation } = this.props;
        this.state = {
            mobile: '',
            pwd: '',
            nickname: '',
        }
    }

    componentWillMount() {

    }

    componentWillUnmount() {

    };

    render() {
        return (
            <View style={{ flex: 1, backgroundColor: Colors.colorEF }}>
                <MyHeader title='创建子账户' leftImg={require('../res/ic_arrow_left.png')} leftClick={() => { this.props.navigation.pop() }} />
                <MyInput1
                    style={{ marginTop: 0 * unitWidth }}
                    onChangeText={this.onMobileTextChange.bind(this)}
                    title={
                        <Text style={{ color: Colors.black, fontSize: 17 }}>*手机号：</Text>
                    }
                    keyboardType='numeric'
                    maxLength={11}
                    placeholder='请输入手机号'
                    value={this.state.mobile} isLast={false} />
                <MyInput1
                    style={{ marginTop: 0 * unitWidth }}
                    onChangeText={this.onPwdTextChange.bind(this)}
                    title={
                        <Text style={{ color: Colors.black, fontSize: 17 }}>*密码：</Text>
                    }
                    maxLength={20}
                    secureTextEntry={true}
                    placeholder='请输入密码'
                    value={this.state.pwd} isLast={false} />
                <MyInput1
                    style={{ marginTop: 0 * unitWidth }}
                    onChangeText={this.onNicknameTextChange.bind(this)}
                    title={
                        <Text style={{ color: Colors.black, fontSize: 17 }}>*昵称：</Text>
                    }
                    maxLength={50}
                    placeholder='请输入昵称'
                    value={this.state.nickname} isLast={true} />
                <SubmitButton1 style={{ marginTop: 200 * unitWidth, alignSelf: 'center' }} text='确定' onPress={() => {
                    this.submit();
                }} />
            </View>
        );
    }

    onMobileTextChange(text) {
        this.setState({
            mobile: text
        })
    }

    onPwdTextChange(text) {
        this.setState({
            pwd: text,
        })
    }

    onNicknameTextChange(text) {
        this.setState({
            nickname: text
        })
    }

    submit() {
        if (this.state.mobile == '') {
            show('请输入手机号');
            return;
        } else if (this.state.pwd == '') {
            show('请输入密码');
            return;
        } else if (this.state.nickname == '') {
            show('请输入昵称');
            return;
        }
        let params = {
            'mobile': this.state.mobile,
            'pwd': this.state.pwd,
            'nickname': this.state.nickname,
        }
        postFetch(api_member_info_SubAccount, params, {
            success: (response) => {
                show('添加成功');
                this.props.navigation.pop();
            },
            fail: (response) => {
                show(response.result.message);
            }
        })
    }
}